<?php

namespace app\admin\model\order;

use think\Model;


class Order extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'order_time_text',
        'gender_text',
        'pay_time_text',
        'departure_time_text',
        'beginserve_time_text',
        'endserve_time_text',
        'cancel_time_text',
        'receiving_time_text',
        'order_status_text',
        'is_store_order_text',
        'payment_type_text',
        'comment_time_text',
        'add_bell_time_text',
        'arrive_time_text',
        'serve_time_text',
        'change_address_text',
    ];
    

    
    public function getGenderList()
    {
        return ['0' => __('Gender 0'), '1' => __('Gender 1')];
    }

    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3'), '4' => __('Order_status 4'), '5' => __('Order_status 5'), '6' => __('Order_status 6'), '7' => __('Order_status 7'), '8' => __('评价完成'), '9' => __('退款成功'), '10' => __('技师拒绝接单'), '11' => __('订单超时未支付自动取消'), '12' => __('技师超时未接单自动取消(已支付)'), '13' => __('已支付取消订单'),'14' => __('加项补差价')];
    }

    public function getIsStoreOrderList()
    {
        return ['0' => __('Is_store_order 0'), '1' => __('Is_store_order 1')];
    }

    public function getPaymentTypeList()
    {
        return ['wechat' => __('Payment_type wechat'), 'alipay' => __('Payment_type alipay'), '3' => __('Payment_type 3')];
    }

    public function getChangeAddressList()
    {
        return ['1' => __('Change_address 1'), '2' => __('Change_address 2')];
    }


    public function getOrderTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_time']) ? $data['order_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDepartureTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['departure_time']) ? $data['departure_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBeginserveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['beginserve_time']) ? $data['beginserve_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndserveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endserve_time']) ? $data['endserve_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCancelTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReceivingTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['receiving_time']) ? $data['receiving_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsStoreOrderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_store_order']) ? $data['is_store_order'] : '');
        $list = $this->getIsStoreOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaymentTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['payment_type']) ? $data['payment_type'] : '');
        $list = $this->getPaymentTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCommentTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['comment_time']) ? $data['comment_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAddBellTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_bell_time']) ? $data['add_bell_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getArriveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['arrive_time']) ? $data['arrive_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getServeTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['serve_time']) ? $data['serve_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getChangeAddressTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['change_address']) ? $data['change_address'] : '');
        $list = $this->getChangeAddressList();
        return isset($list[$value]) ? $list[$value] : '';
    }


//    public function getAppointmentTimeTextAttr($value, $data)
//    {
//        $value = $value ? $value : (isset($data['appointment_time']) ? $data['appointment_time'] : '');
//        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
//    }

    protected function setOrderTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDepartureTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setBeginserveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEndserveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCancelTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReceivingTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCommentTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAddBellTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setArriveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setServeTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

//    protected function setAppointmentTimeAttr($value)
//    {
//        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
//    }


    public function serve()
    {
        return $this->belongsTo('app\admin\model\Serve', 'serve_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function technician()
    {
        return $this->belongsTo('app\admin\model\Technician', 'technician_id', 'technician_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function store()
    {
        return $this->belongsTo('app\admin\model\Store', 'store_id', 'store_id', [], 'LEFT')->setEagerlyType(0);
    }
}
